<?php
/**
 * Created by PhpStorm.
 * User: zengyuming
 * Date: 2017/8/29
 * Time: 上午10:16
 */

namespace Admin\Controller;
class QueryOrderController extends CommonController{
    public function QueryOrder(){
        exit(__METHOD__);
        if(!empty($order_number)){
//            'a.out_trade_no' => $order_number ,
        }
        $Model = M("transaction");
    //$OrderList = $Model->("select a.* , b.appid , b.mch_key from zym_transaction as a left join zym_mch_data as b on a.mch_id = b.mch_id where a.out_trade_no = '{$order_number}' and a.mch_type = 'YinxuntongSMpay' limit 1");
        $OrderInfo = $Model
            ->alias("a")
            ->field('a.* , b.appid , b.mch_key')
            ->join('left join zym_mch_data as b on a.mch_id = b.mch_id')
            ->where(
                array('a.mch_type' => 'YinxuntongSMpay' , 'a.pay_status' => 0 , 'a.create_begtime' => array(array("EGT" ,  1503910800), array('ELT' , 1503914400)))
            )
            ->limit(3)
            ->select();
        foreach($OrderInfo as $value){
            $mch_data = array(
                'mch_id' => $value['mch_id'],
                'appid' => $value['appid'],
                'mch_key' => $value['mch_key']
            );
            $payobj = new \Com\Pay\YinxuntongSMPay($mch_data);
//            ob_clean();
            if($payobj->QueryOrder($value['out_trade_no']) === true){
                // 更新订单状态
                $savedata = array(
                    'pay_status' => 1,
                    'update_begtime' => time()
                );
                $str = $value['out_trade_no']  . '@@@' . $value['paymoney'];
//                file_put_contents('./hello.txt' , $str  .  PHP_EOL, FILE_APPEND);
                echo $str . '<br/>';
//            @$Model->where(array('out_trade_no' => $order_number))->save($savedata);

                // 补发回调通知

            }

        }

    }
}